package com.bb.blog.activiti.cmd;

import com.bb.blog.activiti.common.TaskDeleteReason;
import org.activiti.engine.impl.cmd.NeedsActiveExecutionCmd;
import org.activiti.engine.impl.cmd.NeedsActiveTaskCmd;
import org.activiti.engine.impl.interceptor.CommandContext;
import org.activiti.engine.impl.persistence.entity.ExecutionEntity;
import org.activiti.engine.impl.persistence.entity.TaskEntity;
import org.activiti.engine.impl.persistence.entity.TaskEntityManagerImpl;

public class TaskDelCmd extends NeedsActiveTaskCmd<String> {


    public TaskDelCmd(String taskId) {
        super(taskId);
    }

    @Override
    protected String execute(CommandContext commandContext, TaskEntity task) {
        //获取所需服务
        TaskEntityManagerImpl taskEntityManager = (TaskEntityManagerImpl)commandContext.getTaskEntityManager();
        //获取当前任务的来源任务及来源节点信息
        ExecutionEntity executionEntity = task.getExecution();
        //删除当前任务,来源任务
        taskEntityManager.deleteTask(task,  TaskDeleteReason.JUMP_NODE, false, false);
        return executionEntity.getId();
    }
}
